Skip to content

fix: Potential fix for code scanning alert no. 21: Slice memory allocation with excessive size value#7

Merged
skyoo2003 merged 2 commits intomainfrom
alert-autofix-21
Apr 20, 2026
Merged

fix: Potential fix for code scanning alert no. 21: Slice memory allocation with excessive size value#7
skyoo2003 merged 2 commits intomainfrom
alert-autofix-21

Conversation

@skyoo2003
Copy link
Copy Markdown
Owner

Potential fix for https://github.com/skyoo2003/devcloud/security/code-scanning/21

Add a strict maximum allowed shard count and enforce it in stream creation handling, while preserving existing behavior for valid inputs.

Best single fix:

  • In internal/services/kinesis/provider.go, validate ShardCount in createStream after reading it with intParam.
  • If ShardCount is out of range, return a ValidationException (HTTP 400) and do not call the store.
  • Keep existing default behavior (default 1) and avoid changing storage internals/function signatures.

Why here: validation belongs at the API boundary where user input is interpreted, and it prevents all downstream variants (including the sink in store.go) with one guard.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

… with excessive size value

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@github-actions github-actions Bot added the services AWS service implementations label Apr 19, 2026
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Apr 19, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds strict validation of the Kinesis stream ShardCount parameter at the provider API boundary to prevent excessive or invalid slice allocations, returning a ValidationException for out-of-range values while preserving existing defaults and internals.

File-Level Changes

Change Details Files
Validate ShardCount in createStream and reject out-of-range values with a Kinesis-style ValidationException before calling the store.
  • Introduce a local constant maxShardCount set to 1024 within createStream.
  • After parsing ShardCount with intParam (defaulting to 1), check that it is greater than 0 and less than or equal to maxShardCount.
  • If ShardCount is outside the allowed range, return a jsonErr ValidationException with HTTP 400 and message "ShardCount must be between 1 and 1024" without proceeding further in createStream.
internal/services/kinesis/provider.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@skyoo2003 skyoo2003 changed the title Potential fix for code scanning alert no. 21: Slice memory allocation with excessive size value fix: Potential fix for code scanning alert no. 21: Slice memory allocation with excessive size value Apr 19, 2026
@skyoo2003 skyoo2003 self-assigned this Apr 19, 2026
@skyoo2003 skyoo2003 marked this pull request as ready for review April 19, 2026 18:51
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • The hardcoded 1024 in the error message could easily drift from maxShardCount; consider formatting the message using the maxShardCount constant instead of duplicating the literal.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The hardcoded `1024` in the error message could easily drift from `maxShardCount`; consider formatting the message using the `maxShardCount` constant instead of duplicating the literal.

## Individual Comments

### Comment 1
<location path="internal/services/kinesis/provider.go" line_range="203-204" />
<code_context>
 		return jsonErr("ValidationException", "StreamName is required", http.StatusBadRequest), nil
 	}
 	shardCount := intParam(params, "ShardCount", 1)
+	if shardCount <= 0 || shardCount > maxShardCount {
+		return jsonErr("ValidationException", "ShardCount must be between 1 and 1024", http.StatusBadRequest), nil
+	}
 	mode := "PROVISIONED"
</code_context>
<issue_to_address>
**suggestion:** Avoid hardcoding the upper bound in the error message to keep it consistent with `maxShardCount`.

The validation already relies on `maxShardCount`, but the message still hardcodes `1024`, which could become misleading if `maxShardCount` changes. Consider formatting the error string with `maxShardCount` so it always reflects the actual limit.

Suggested implementation:

```golang
	if shardCount <= 0 || shardCount > maxShardCount {
		return jsonErr("ValidationException", fmt.Sprintf("ShardCount must be between 1 and %d", maxShardCount), http.StatusBadRequest), nil
	}

```

1. Ensure `fmt` is imported at the top of `internal/services/kinesis/provider.go`:
   - If not already present, add `fmt` to the import block, e.g.:
     `import ("fmt" /* existing imports... */)`.
2. If the file uses grouped imports, keep `fmt` alphabetically ordered with the existing imports to match project conventions.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread internal/services/kinesis/provider.go Outdated
@github-actions github-actions Bot added the bug Something isn't working label Apr 20, 2026
@skyoo2003 skyoo2003 merged commit a9e2f31 into main Apr 20, 2026
10 checks passed
@skyoo2003 skyoo2003 deleted the alert-autofix-21 branch April 20, 2026 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working services AWS service implementations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant